package color.koitq.picker.activty;

import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import color.koitq.picker.R;
import color.koitq.picker.ad.AdActivity;
import color.koitq.picker.adapter.ColorAdapter;
import color.koitq.picker.decoration.GridSpaceItemDecoration;
import color.koitq.picker.entity.ColorModel;
import color.koitq.picker.util.Util;

public class InspirationActivity extends AdActivity {
    @BindView(R.id.topbar)
    QMUITopBarLayout topbar;
    @BindView(R.id.list)
    RecyclerView list;
    @BindView(R.id.tv)
    TextView tv;
    private ColorAdapter mAdapter;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_inspriration;
    }

    @Override
    protected void init() {
        topbar.setTitle("灵感");
        topbar.addLeftBackImageButton().setOnClickListener(v -> finish());
        initList();
        showSecondPageAd_TwoBanner(findViewById(R.id.bannerView),findViewById(R.id.bannerView2));
    }

    private void initList() {
        list.setLayoutManager(new GridLayoutManager(activity, 8));
        mAdapter = new ColorAdapter();
        List<ColorModel> colorList = new ArrayList<>();
        for (int i = 0; i < 160; i++) {
            ColorModel colorModel = new ColorModel();
            colorModel.color="#000000";
            colorList.add(colorModel);
        }
        mAdapter.setNewInstance(colorList);
        list.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            tv.setVisibility(View.GONE);
            ColorModel item = mAdapter.getItem(position);
            item.color=Util.getRandomColor();
            mAdapter.notifyItemChanged(position);
        });
    }
}
